//
// Created by binny on 2022/6/14.
//

#include "mytime.h"


Time::Time() {
    hours = minutes = 0;
    std::cout << "默认构造函数" << std::endl;
}

Time::Time(Time &time) {
    hours = time.hours;
    minutes = time.minutes;
    std::cout << "拷贝构造函数" << std::endl;
}

Time::Time(int h, int m) {
    hours = h;
    minutes = m;
    std::cout << "双参构造函数" << std::endl;
}

Time::~Time() {
    std::cout << "析构函数" << std::endl;
}

void Time::addHr(int h) {
    hours += h;
    std::cout << "addHr 函数" << std::endl;
}

void Time::addMin(int m) {
    minutes += m;
    std::cout << "addMin 函数" << std::endl;
}

void Time::reset(int h, int m) {
    hours = h;
    minutes = m;
    std::cout << "reset 函数" << std::endl;
}

void Time::show() const {
    std::cout << "hours = " << hours << " ;minutes = " << minutes << std::endl;
    std::cout << "show 函数" << std::endl;
}

Time Time::sum(const Time &t) const {
    std::cout << "sum 函数参数的地址 = " << &t << std::endl;
    Time time;//调用默认构造函数
    std::cout << "局部函数对象的地址 = " << &time << std::endl;
    time.minutes = this->minutes + t.minutes;
    time.hours = this->hours + t.hours + time.minutes / 60;
    time.minutes %= 60;
    std::cout << "sum 函数" << std::endl;
    return time;
}